package com.springboot.admin.exception;

import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/************************************************************************
 *
 *    Copyright  Copyright 2021 Google Inc.
 *    File Name: CustomerHandlerExceptionResolver
 *    Description: 自定义异常解析器
 *
 *    Version: V1.0
 *    Author: Fuc
 *    Create Time: 2021-01-08
 *
 *************************************************************************/

@Order(value = Ordered.HIGHEST_PRECEDENCE) // 优先级，数字越小优先级越高
@Component
public class CustomerHandlerExceptionResolver implements HandlerExceptionResolver {

  @Override
  public ModelAndView resolveException(
      HttpServletRequest request,
      HttpServletResponse response,
      Object object,
      Exception exception) {
    try {
      response.sendError(511, "我喜欢的错误");
    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }
}
